package com.yoomiito.app.ui.my.youmi;

import com.yoomiito.app.base.AppConfig;
import com.yoomiito.app.base.BaseActPresenter;
import com.yoomiito.app.model.my.YouMI;
import com.yoomiito.app.net.YmApi;

import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.XApi;

public class YouMiPresenter extends BaseActPresenter<YouMiActivity> {

    public YouMiPresenter(AppConfig appConfig) {
        super(appConfig);
    }

    public void getYouBi() {
        YmApi.getYmService()
                .getYoumi()
                .compose(getV().bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(new ApiSubscriber<YouMI>(handleException()) {
                    @Override
                    public void onSuccess(YouMI youMI) {
                        if (hasV())
                            getV().setYouMi(youMI);
                    }

                    @Override
                    public void onFail(ApiException error) {
                        if (hasV())
                            getV().dismissLoading();
                    }
                });
    }
}
